package chapter06

/**
 * Created with IntelliJ IDEA.
 * ClassName: Test15_TraitOverlying
 * Package: chapter06
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 *          Date: 2023-06-23
 *          Time: 19:29
 */

//特质的叠加
object Test15_TraitOverlying {
  def main(args: Array[String]): Unit = {
    val s = new Student15
    s.increase() //k

    //钻石问题特征叠加
    val foot = new Foot
    println(foot.des())

  }
}

//定义球类特征
trait Ball {
  def des(): String = "ball"
}

//定义颜色特征
trait Color extends Ball {
  var color: String = "rad"
  override def des(): String = color + "_" + super.des()
}

//定义种类特征
trait Cate extends Ball {
  var cate: String = "foot"
  override def des(): String = cate + "_" + super.des()
}
//自定义球
class Foot extends Cate with Color{
  //钻石问题特征叠加 my ball is a rad_foot_ball
  override def des(): String = "my ball is a " + super.des()
}


//学生的天赋 不一定所有的学生都用天赋
trait Talent15 {
  def singing(): Unit

  def dancing(): Unit

  def increase(): Unit = {
    println("T inc")
  }
}

//在定义一个特质
trait Knowledge15 {
  var amount: Int = 0

  def increase(): Unit = {
    println("K inc")
  }
}

class Student15 extends Person13 with Talent15 with Knowledge15 {
  //
  override def singing(): Unit = println("singing")

  override def dancing(): Unit = println("dancing")

  //因为都有increase 所以必须重写
  override def increase(): Unit = {
    //而且这里调用的super是谁 是从后往前调用了Know的increase
    super.increase()
  }
}